<template>
  <div class="review-info">
    <div>
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <el-form-item label="活动名称" prop="title">
          <el-input v-model.trim="form.title"></el-input>
        </el-form-item>
        <el-form-item label="业务范围">
          <ExtFiledSelect
            v-if="form.title"
            :defaultValue="form.ruleVO.courseType"
            @emit="setExtFiled"
            disabled
            :scoped="[0, 6]"
          />
        </el-form-item>
        <el-form-item label="承办单位" prop="addr">
          <el-input v-model.trim="form.addr"></el-input>
        </el-form-item>
        <!-- <el-form-item label="内容">
          <el-input v-model.trim="form.content"></el-input>
        </el-form-item> -->
        <el-form-item label="起止时间" prop="date">
          <el-date-picker
            v-model="form.date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="描述">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入描述"
            v-model="form.des"
          >
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="custom" v-preventReClick @click="submitForm('form')"
        >保 存</el-button
      >
    </span>
  </div>
</template>
<script>
import { expertsReviewUpdate } from '@/api/admin/audit/expertsReview.js'
import { getSession, setSession } from '@/utils/session'
export default {
  components: {
    ExtFiledSelect: () => import('@/components/dataSelect/extFiledSelect'),
  },
  data() {
    return {
      form: {
        // courseType: '',
        title: '', //活动名称
        date: [],
        addr: '', //地址
        content: '', //内容
        extFiled: '',
        startTime: '',
        endTime: '',
        status: '1', //状态，1-待评审，2-评审中，3-评审完成
        des: '', //描述
        ruleVO: {
          courseType: '',
          deptId: '',
          rule1: '',
          rule2: '',
        },
      },
      rules: {
        title: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
        addr: [{ required: true, message: '请输入承办单位', trigger: 'blur' }],
        courseType: [
          { required: true, message: '请选择业务范围', trigger: 'blur' },
        ],
        date: [{ required: true, message: '请选择起止时间', trigger: 'blur' }],
      },
    }
  },
  mounted() {
    let reviewData = JSON.parse(getSession('reviewData'))
    this.init(reviewData)
  },
  methods: {
    //显示弹窗
    init(row) {
      if (row) {
        this.form = { ...this.form, ...row }
        this.form.date = [this.form.startTime, this.form.endTime]
        this.form.ruleVO = JSON.parse(row.extFiled)
        // this.form.courseType = this.form.ruleVO.courseType
        this.$set(this.form, 'id', row.id)
      } else {
        this.form = this.$options.data().form
        this.$delete(this.form, 'id')
      }
    },
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.form.startTime = this.form.date[0]
          this.form.endTime = this.form.date[1]
          this.form.date = undefined
          this.edit()
        }
      })
    },
    setExtFiled(v) {
      this.form.courseType = v
      this.form.ruleVO.courseType = v
    },
    //编辑
    edit() {
      expertsReviewUpdate(this.form).then((res) => {
        this.done(res)
      })
    },
    done(res) {
      if (!res || res.data.code != 0) return
      setSession('reviewData', JSON.stringify(this.form))
      this.form.date = [this.form.startTime, this.form.endTime]
      this.$message({
        message: '操作成功',
        type: 'success',
      })
    },
  },
}
</script>
<style scoped>
.review-info {
  max-width: 600px;
}
</style>